def isPrime(n):
    for i in range(2,int(n**0.5)+1):
        if n%i==0:
            return False
    return True
n=int(input())
if n> 999 and n<10000:
    
    

    n1=n//1000
    n2=(n//100)%10
    n3=(n//10)%10
    n4=n%10

    MaxPrime=0

    if isPrime(n1) and MaxPrime<n1: MaxPrime=n1
    if isPrime(n2) and MaxPrime<n1: MaxPrime=n2
    if isPrime(n3) and MaxPrime<n1: MaxPrime=n3
    if isPrime(n4) and MaxPrime<n1: MaxPrime=n4

    n12=n1*10+n2
    if isPrime(n12) and MaxPrime<n12: MaxPrime=n12
    n13=n1*10+n3
    if isPrime(n13) and MaxPrime<n13: MaxPrime=n13
    n14=n1*10+n4
    if isPrime(n14) and MaxPrime<n14: MaxPrime=n14

    n23=n2*10+n3
    if isPrime(n23) and MaxPrime<n23: MaxPrime=n23
    n24=n2*10+n4
    if isPrime(n24) and MaxPrime<n24: MaxPrime=n24

    n34=n3*10+n4
    if isPrime(n34) and MaxPrime<n34: MaxPrime=n34

    n123=n1*100+n2*10+n3
    if isPrime(n123) and MaxPrime<n123: MaxPrime=n123

    n134=n1*100+n3*10+n4
    if isPrime(n134) and MaxPrime<n134: MaxPrime=n134
 
    n234=n2*100+n3*10+n4
    if isPrime(n234) and MaxPrime<n234: MaxPrime=n234

    if isPrime(n) and MaxPrime<n: MaxPrime=n

    print(MaxPrime)
else: print('0')













